import mongoose from "mongoose";
import uniqueValidator from "mongoose-unique-validator";

const conversationScheme = new mongoose.Schema(
  {
    participants: [
      {
        type: mongoose.Schema.Types.ObjectId,
        ref: "User",
      },
    ],
    messages: [
      {
        type: mongoose.Schema.Types.ObjectId,
        ref: "Message",
        default: [],
      },
    ],
  },
  { timestamps: true }
);

conversationScheme.plugin(uniqueValidator, { message: "is already taken" });
const Conversation =
  mongoose.models.Conversation ||
  mongoose.model("Conversation", conversationScheme);

export default Conversation;
